package com.xtravel.discovery.viewholder;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import com.lidroid.xutils.BitmapUtils;
import com.xtravel.R;
import com.xtravel.discovery.activity.CountryLiveItemsActivity;
import com.xtravel.discovery.adapter.LiveItemImageListAdapter;
import com.xtravel.discovery.dto.StateLiveRecord;
import com.xtravel.discovery.widget.NoScrollGridViewEx;

/**
 * Created by memory on 15/12/5.
 */
public final class StateLiveRecordsViewHolder extends BaseViewHolder<StateLiveRecord>{
    private TextView liveMainTitle;
    private NoScrollGridViewEx scrollGridView;
    private ImageButton moreButton;

    public StateLiveRecordsViewHolder(Context context, BitmapUtils bitmapUtils, LayoutInflater layoutInflater)
    {
        super(context, bitmapUtils, layoutInflater);
    }

    @Override
    public View getView() {
        View convertView = layoutInflater.inflate(R.layout.live_records_list_item_more, null);
        this.liveMainTitle = (TextView) convertView.findViewById(R.id.live_main_title);
        this.scrollGridView = (NoScrollGridViewEx) convertView.findViewById(R.id.country_record_list);
        this.moreButton = (ImageButton)convertView.findViewById(R.id.country_live_more);
        this.moreButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                StateLiveRecord record = (StateLiveRecord)view.getTag();
                Intent intent = new Intent(context, CountryLiveItemsActivity.class);
                intent.putExtra("name", record.countryName);
                intent.putExtra("code", record.countryCode);
                context.startActivity(intent);
            }
        });
        convertView.setTag(this);
        return convertView;
    }

    @Override
    public void setValue(StateLiveRecord record) {
        this.moreButton.setTag(record);
        this.liveMainTitle.setText(record.countryName);
        this.scrollGridView.setAdapter(new LiveItemImageListAdapter(this.context, this.bitmapUtils, record.lives));
    }
}
